﻿using System;
using System.Collections.Generic;
using System.Reflection;
using COC.Character;
using COC.Character.AI.Internal.FSM;
using UnityEngine;
using COC.Debug;
namespace COC.Tools.AI.Motion
{
    /// <summary>
    /// awaring if ai attached a ai behave,as well as interaction with <see cref="COC.Character.AI.Internal.FSM.FSMConnector">FSMConnector</see> class.
    /// </summary>
    public class AIBehaveAware
    {
        protected internal int id;//id
        protected internal int playerId;
        protected internal Transform t;
        protected internal Vector3 agentPos;
        protected internal Vector3 targetPos;
        protected internal Vector3 velocity;
        //protected internal Vector3 angleVelocity;
        protected internal float max_velocity;
        protected internal Quaternion rotation;
        FSMConnector mConnector;
        #region following path
        protected internal Vector3 currentPathPoint = Vector3.zero;
        protected internal int indexOfCurrentPathPoint;
        protected internal float tmrTimeSpentOnPathPoint;
        protected internal float nextNodeDistance;//set the distance between next node and current position.
        protected internal bool loopPath;
        protected internal GameObject go;
        #endregion
        #region proprtietrary
        protected internal float CENTER_OF_RADIUS = 2.0f;
        protected internal Vector3 centerVect3 = Vector3.zero;

       /* public AIBehaveAware(object target)
        {
            Type t = target.GetType().BaseType;
            if (t != null && t == typeof(BaseBehaviourSupport) || t == typeof(BaseBehaviour) || t == typeof(MonoBehaviour))
            {
                Vector3 pos=((MonoBehaviour)target).transform.position;
                centerVect3 = pos;
            }
            else
            {
                Debug.LogWarning("could not find this class: " + target.GetType().Name + " that inheritanted of supported type");
            }
        }*/

        #endregion
        #region leader
        protected internal bool isLeader;
        protected internal AIBehaveAware leader;
        #endregion
        #region interaction with AIBehave
        AIBehave aiBehave;
        #endregion

        public AIBehaveAware()
        {

        }
        /// <summary>
        /// new instance a FSMConnector by pass fSMC reference in if not set
        /// </summary>
        /// <param name="_baseBehaviour"></param>
        /// <param name="fSMC"></param>
        /// <param name="states"></param>
        public void wireFSMConnector(BaseBehaviour _baseBehaviour, FSMConnector fSMC, Type states)
        {
            if (fSMC == null)
            {
                mConnector = new FSMConnector(_baseBehaviour);
            return;
            }
            mConnector = null;
            mConnector = fSMC;
            
        }
        public override bool Equals(object obj)
        {
            AIBehaveAware target=(AIBehaveAware)obj;
           if(target.id==this.id)
           {
               return true;
           }
           return false;
        }
      /*  /// <summary>
        /// attach on AIBehave class
        /// </summary>
        public void onAttach(FSMConnector connector)
        {
            go.GetComponent<AIBehave>().connector = connector;

            go.GetComponent<AIBehave>().open(true);
        }
        /// <summary>
        /// dettach on AIBehave class
        /// </summary>
        public void onDettach()
        {
            go.GetComponent<AIBehave>().connector = null;
            go.GetComponent<AIBehave>().open(false);
        }*/
        public void parseState(AiAction action)
        {
            DebugTool.Log(action.state.ToString(), null);
           // string methodStr=action.methodName;

            
        }
       


    }

}
